﻿using HDS.Common.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HDS.Common.WordProcessing
{
    public class RoomNameEngHelper
    {
        /// <summary>
        /// 将英文房型名称生成编码
        /// </summary>
        /// <param name="roomNameEng"></param>
        /// <returns></returns>
        public static string GetSupplierRoomId(string roomNameEng)
        {
            if (string.IsNullOrEmpty(roomNameEng))
                return "";

            roomNameEng = roomNameEng.ToLower().RemoveNotLetterNumber().ReplaceMultSpaceToOne();
            roomNameEng = GetStemWord(roomNameEng);

            var arr1 = roomNameEng.Split(' ').OrderBy(a => a).ToArray();

            roomNameEng = string.Join(" ", arr1);

            return roomNameEng.CreateMD5().CreateMD5().Substring(0, 8).ToLower();
        }


        /// <summary>
        /// 转换成词干
        /// </summary>
        /// <param name="roomNameEng"></param>
        /// <returns></returns>
        private static string GetStemWord(string roomNameEng)
        {
            var strArr = roomNameEng.ToLower().Split(' ');
            var t_roomName = "";
            var stemmer = new PorterStemmer();
            foreach (var str in strArr)
            {
                var stem = stemmer.StemWord(str);
                t_roomName += stem + " ";
            }
            return t_roomName;
        }
    }
}
